﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Chat_D_LuX_Client
{
    /// <summary>
    /// Interaction logic for CreateRoom.xaml
    /// </summary>
    public partial class CreateRoom : Window
    {
        public string roomName { get; set; }

        public CreateRoom()
        {
            InitializeComponent();
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btnCreateRoom_Click(object sender, RoutedEventArgs e)
        {
            bool isTaken = false;
            ChatServiceRef.Chat_ServiceClient csr = new ChatServiceRef.Chat_ServiceClient();
            
            //TODO try catch this
            isTaken =  csr.RoomExists(txtRoomName.Text.ToString());

            if (!isTaken)
            {
                // Create room
                csr.CreateRoom(txtRoomName.Text, txtDescription.Text);

                //assign roomname so parent form can access it
                this.roomName = txtRoomName.Text.ToString();
                this.DialogResult = true;
                this.Close();
            }
            else
            {
                //tell user room taken
                MessageBox.Show("The room name was taken, try a different name!");
            }
        }
    }
}
